<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title></title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all"/>
    <style>
        .layui-form-item .layui-input-inline {
            width: 150px;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title layui_tab_title">
                <li><a href="{:url('worldcup/index')}">赛事</a></li>
                <li><a href="{:url('worldcup/point')}">积分</a></li>
                <li><a href="{:url('worldcup/rank')}">晋级图</a></li>
                <li class="layui-this"><a href="{:url('WorldCupGuess/index')}">竞猜</a></li>
                <li><a href="{:url('WorldCupGuess/order')}">竞猜记录</a></li>
            </ul>
        </div>

        <form class="layui-form" id="sbumitForm">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline ">
                        <div class="layui-input-inline" style="width: 150px">
                            <select name="group_code" lay-filter="group_code">
                                <option value="A">A组</option>
                                <option value="B">B组</option>
                                <option value="C">C组</option>
                                <option value="D">D组</option>
                                <option value="E">E组</option>
                                <option value="F">F组</option>
                                <option value="G">G组</option>
                                <option value="H">H组</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
        </form>
        <div class="layui-card-body layui-table-body layui-table-main">
            <table id="demo" lay-filter="demo"></table>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: "/layuiadmin/" //静态资源所在路径
    }).extend({
        index: "lib/index", //主入口模块
    }).use(["table", 'form'], function () {
        $ = layui.jquery, form = layui.form, table = layui.table;
        table.render(table_conf());
        form.on('select(group_code)', function (data) {
            table.render(table_conf());
        });
    });

    function table_conf() {
        return {
            elem: '#demo',
            id: '#demo',
            url: '/admin/world_cup_guess/index?' + $("#sbumitForm").serialize(),
            page: {
                curr: 1   //默认从第一页开始搜索
            },
            method: "get",
            //where: $("#sbumitForm").serialize(),
            limit: 20,
            limits: [20, 30, 50, 100, 200, 500],
            text: {
                none: '暂无相关数据！'//默认无数据
            },
            response: {
                statusName: 'code', //数据状态的字段名称，默认：code
                statusCode: 0,//成功的状态码，默认：0
                msgName: 'msg', //状态信息的字段名称，默认：msg
                countName: 'count', //数据总数的字段名称，默认：count
                dataName: 'list', //数据列表的字段名称，默认：data
            },
            cols: [[
                {field: 'team_name', width: 220, title: '球队', align: 'center'},
                {field: 'group_code', width: 120, title: '小组', align: 'center'},
                {field: 'odds', width: 150, title: '当前赔率', align: 'center'},
                {field: 'diamond', width: 160, title: '投注总额(宝石)', align: 'center'},
                {field: 'settle_diamond', width: 160, title: '赔付总额(宝石)', align: 'center'},
                {
                    field: '', width: 135, title: '状态', align: 'center', templet: function (item) {
                        if (item.open_status) {
                            switch (item.open_status) {
                                case 1:
                                    return '夺得冠军';
                                case 2:
                                    return '已淘汰';
                            }
                        }

                        switch (item.status) {
                            case 1:
                                return '销售中';
                            case 2:
                                return '已封盘';
                        }

                        return '-';
                    }
                },

                {
                    field: '', title: '操作', align: 'center', templet: function (item) {
                        var html = '';
                        if (item.open_status) {
                            return html;
                        }

                        html += '<a class="layui-btn layui-btn-xs" onclick="set_odds(' + item['id'] + ',\'' + item['odds'] + '\',\'' + item['team_name'] + '\')"><i class="layui-icon"></i>调整赔率</a>';
                        html += '<a class="layui-btn layui-btn-xs" onclick="eliminate(' + item['id'] + ',\'' + item['team_name'] + '\')" style="background-color: red"><i class="layui-icon"></i>设置淘汰</a>';
                        if (item.status == 1) {
                            html += '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="closed(' + item['id'] + ',\'' + item['team_name'] + '\')"><i class="layui-icon"></i>封盘</a>';
                        }

                        html += '<a class="layui-btn layui-btn-xs" onclick="champion(' + item['id'] + ',\'' + item['team_name'] + '\')" style="background-color: #1E9FFF"><i class="layui-icon"></i>赢得冠军</a>';
                        return html;
                    }
                },
            ]],
            done: function (res, curr, count) {
                res.list.forEach(function (item, index) {

                });
            },
        };
    }

    function set_odds(id, odds, team_name) {
        var html = '<style>.layui-layer-dialog .layui-layer-content{padding:10px;}.layui-layer-btn{padding:0px 24px 0px 0px;}.layui-layer-title{padding:0px;}</style><div class="layui-card-body" style="padding:0px;">'
            + '<form action="" method="post" id="oddsfrom">'

            + '<div class="layui-row layui-col-space10 layui-form-item">'

            + '<div class="layui-col-lg6"><label class="layui-form-label">当前赔率：</label>'
            + '<div class="layui-input-block">'
            + '<input type="text" name=""  autocomplete="off" class="layui-input" value="' + odds + '" style="width: 300px;color: #999" readonly="readonly"/>'
            + '</div></div>'

            + '</div>'

            + '<div class="layui-row layui-col-space10 layui-form-item">'

            + '<div class="layui-col-lg6"><label class="layui-form-label">调整赔率：</label>'
            + '<div class="layui-input-block">'
            + '<input type="text" name="odds"  autocomplete="off" class="layui-input" value="" style="width: 300px;" id="odds"/>'
            + '</div></div>'

            + '</div>';

        +'</form>'
        + '</div>';
        layer.confirm(html, {
            area: ['460px', '250px'],
            title: '<div style="width: 100%;text-align: center"><strong>' + team_name + '</strong></div>'
        }, function (index) {
            $.ajax({
                type: "POST",//请求方式
                url: "/admin/world_cup_guess/setodds", //请求地址
                dataType: "json",//返回的数据类型
                data: {"id": id, "odds": $("#odds").val()},
                beforeSend: function (data) {
                    if (!$("#odds").val()) {
                        layer.msg('调整赔率不能为空', {icon: 2});
                        return false;
                    }
                },
                //请求成功
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 2000}, function () {
                            window.location.reload();
                        });
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                //请求失败，包含具体的错误信息
                error: function (e) {
                }
            });
        });
    }

    function eliminate(id, team_name) {
        var html = '<strong>将【' + team_name + '】设置为淘汰,投注【' + team_name + '】的用户将会判定为输</strong>';
        layer.confirm(html, {area: ['380px', '220px'], title: '提示'}, function (index) {
            $.ajax({
                type: "POST",//请求方式
                url: "/admin/world_cup_guess/eliminate", //请求地址
                dataType: "json",//返回的数据类型
                data: {"id": id},
                //请求成功
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 2000}, function () {
                            window.location.reload();
                        });
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                //请求失败，包含具体的错误信息
                error: function (e) {
                }
            });
        });
    }

    function closed(id, team_name) {
        var html = '<strong>将【' + team_name + '】设置为封盘</strong>';
        layer.confirm(html, {area: ['380px', '220px'], title: '提示'}, function (index) {
            $.ajax({
                type: "POST",//请求方式
                url: "/admin/world_cup_guess/closed", //请求地址
                dataType: "json",//返回的数据类型
                data: {"id": id},
                //请求成功
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 2000}, function () {
                            window.location.reload();
                        });
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                //请求失败，包含具体的错误信息
                error: function (e) {
                }
            });
        });
    }

    function champion(id, team_name) {
        var html = '<strong>将【' + team_name + '】设置为冠军,投注【' + team_name + '】的用户将会判定为赢</strong>';
        layer.confirm(html, {area: ['380px', '220px'], title: '提示'}, function (index) {
            $.ajax({
                type: "POST",//请求方式
                url: "/admin/world_cup_guess/champion", //请求地址
                dataType: "json",//返回的数据类型
                data: {"id": id},
                //请求成功
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 2000}, function () {
                            window.location.reload();
                        });
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                //请求失败，包含具体的错误信息
                error: function (e) {
                }
            });
        });
    }
</script>
</body>
</html>
